package unipi.helpers;

import java.util.List;

public class Table
{
	private int ncols;
	private String html;
	private boolean done;
	
	public Table(List<String> coltitles)
	{
		ncols = coltitles.size();
		done = false;
		
		html = "<table class=\"tabla\"><thead><tr>";
		
		for(int x = 0; x < ncols; x++)
		{
			html += "<td>" + coltitles.get(x) + "</td>";
			
		}
		
		html += "</tr></thead><tbody>";
	}
	
	public boolean addRow(List<String> row, boolean even)
	{
		if(row.size() != ncols || done)
			return false;
		
		String s = (even)?"even":"odd2";
		
		html += "<tr class=\"fillerRow\"><td  class=\"fillerCol\"></td></tr>";
		html += "<tr class = \"" + s + "\">";
		
		for(int x = 0; x < ncols; x++)
		{
			html += "<td>" + row.get(x) + "</td>";			
		}
		
		html += "</tr>";
		
		return true;
		
	}
	
	public void addFillerRow(String row, boolean even)
	{	
		String s = (even)?"even":"odd";
		html += "<tr class=\"fillerRow\"><td  class=\"fillerCol\"></td></tr>";
		html += "<tr class = \"" + s + "\">";
		html += "<td colspan=\"" + ncols + "\">" + row + "</td></tr>";
	}
	
	public void addExplicitRow(String fullRowHTML)
	{
		html += fullRowHTML;
	}
	
	public String getHTML()
	{
		html += "</tbody></table>";	
		done = true;
		
		return html;		
	}

}
